const joi = require("joi");

const title = joi.string().min(1).required();
const time = joi.array().required().items(joi.number());
const attention = joi.string().allow("");
const createTime = joi.number().required();
const items = joi
  .array()
  .required()
  .items(
    joi.object().keys({
      id: joi.number(),
      testId: joi.number(),
      itemTitle: joi.string().required(),
      itemContent: joi.string().required(),
      score: joi.number().required(),
      resultExample: joi.string().allow(""),
      resultExamplePic: joi.array().items(
        joi.object().keys({
          url: joi.string().required(),
          name: joi.string(),
        })
      ),
      contentPic: joi.array().items(
        joi.object().keys({
          url: joi.string().required(),
          name: joi.string(),
        })
      ),
      file: joi.array().items(
        joi.object().keys({
          url: joi.string().required(),
          name: joi.string(),
        })
      ),
    })
  );
exports.publishTest = {
  body: {
    title,
    time,
    items,
    attention,
    createTime,
    submitTimes: createTime
  },
};
const id = joi.string().required();
const testId = joi.number().required();
exports.getTestDetail = {
  query: {
    id,
    testId,
  },
};

const userId = joi.string().required();
const list = joi.array().items(
  joi.object().keys({
    answer: joi.string().max(10000).allow(""),
    answerFile: joi.array().items(joi.object().keys({
      url: joi.string().required(),
      name: joi.string().allow(null)
    })),
    testDetailId: joi.number().required()
  })
);
exports.submitTest = {
  body: {
    userId,
    list,
    testId,
  },
};

exports.resubmitTest = {
  body:{
    testId,
    userId,
    list : joi.array().items(
      joi.object().keys({
        id:joi.number().required(),
        answer: joi.string().max(10000).allow(""),
        answerFile: joi.array().items(joi.object().keys({
          url: joi.string().required(),
          name: joi.string().allow(null)
        })),
      })
    )
  }
}
exports.giveScore = {
  body:{
    testId,
    userId,
    list : joi.array().items(
      joi.object().keys({
        id:joi.number().required(),
        getScore:joi.number().required(),
      })
    )
  }
}